package com.example.shiptask.parser;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.example.shiptask.entity.MakeToOrderEntivity;
import com.example.shiptask.entity.NumberEntivity;
import com.example.shiptask.util.JsonUtil;

public class MakeToOrderParser implements AllParse{

	private static List<Object> list;
	private static MakeToOrderEntivity entivity;
	private static JSONObject obj;
	private NumberEntivity entivity2;
	public List<Object> parse(String json) {
		try {
			obj=new JSONObject(json);
			
			JSONArray  ary=obj.getJSONArray("content");
			Log.i("CONTent", "content="+ary);
			list=new ArrayList<Object>();
			for(int i=0;i<ary.length();i++){
				JSONObject object=ary.getJSONObject(i);
				entivity=new MakeToOrderEntivity();
				entivity.setId(JsonUtil.getJsonValue(object,"id"));
				entivity.setCode(JsonUtil.getJsonValue(object,"code"));
				entivity.setCargoName(JsonUtil.getJsonValue(object,"cargoName"));
				entivity.setStartPort(JsonUtil.getJsonValue(object,"startPort"));
				entivity.setEndPort(JsonUtil.getJsonValue(object,"endPort"));
				entivity.setrAmount(JsonUtil.getJsonValue(object,"rAmount"));
				entivity.setCargoUnits(JsonUtil.getJsonValue(object,"cargoUnits"));
				entivity.setAccountMethod(JsonUtil.getJsonValue(object,"accountMethod"));
				entivity.setFare(JsonUtil.getJsonValue(object,"fare"));
				entivity.setLoadTime(JsonUtil.getJsonValue(object,"loadTime"));
				entivity.setLoadRequire(JsonUtil.getJsonValue(object,"loadRequire"));
				entivity.setFareUnit(JsonUtil.getJsonValue(object,"fareUnit"));
				entivity.setIncludePCF(JsonUtil.getJsonValue(object,"fareUnit"));
				list.add(entivity);
				System.out.println("ENTIVITY="+entivity.toString());
			}
			System.out.println("LIST="+list.toString());

		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	public NumberEntivity getNumber(String json){
		try {
	        JSONObject obj1 = new JSONObject(json);
	        entivity2 = new NumberEntivity();
			entivity2.setPage(obj1.getInt("page"));
			entivity2.setSize(obj1.getInt("size"));
			entivity2.setTotal(obj1.getInt("total"));
			entivity2.setPages(obj1.getInt("pages"));
        } catch (JSONException e) {
	        e.printStackTrace();
        }
		return entivity2;
		
	}

}
